package com.esri.core.renderer;

import com.esri.core.geometry.Geometry;
import com.esri.core.internal.util.d;
import com.esri.core.map.Feature;
import com.esri.core.map.FeatureTemplate;
import com.esri.core.map.Graphic;
import com.esri.core.map.WebMapQuery;
import com.esri.core.symbol.Symbol;
import com.esri.core.symbol.SymbolHelper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonNode;

/* loaded from: classes.dex */
public class ClassBreaksRenderer extends BaseRenderer {
    public static final String TYPE = "classBreaks";
    private static final long serialVersionUID = 1;
    String d;
    double e;
    TreeMap<Double, ClassBreak> f;
    Symbol g;
    String h;
    NormalizationType i;
    String j;
    double k;

    @Override // com.esri.core.renderer.BaseRenderer
    protected String getType() {
        return TYPE;
    }

    public ClassBreaksRenderer() {
        this.f = new TreeMap<>();
        this.g = null;
        this.h = null;
        this.i = NormalizationType.None;
    }

    public ClassBreaksRenderer(JsonNode jsonNode) throws Exception {
        super(jsonNode);
        this.f = new TreeMap<>();
        this.g = null;
        this.h = null;
        this.i = NormalizationType.None;
        if (jsonNode == null) {
            return;
        }
        JsonNode jsonNode2 = jsonNode.get(WebMapQuery.PARAM_FIELD);
        if (jsonNode2 != null && !jsonNode2.isNull()) {
            this.d = jsonNode2.getTextValue();
        }
        JsonNode jsonNode3 = jsonNode.get("normalizationType");
        if (jsonNode3 != null && !jsonNode3.isNull()) {
            this.i = NormalizationType.fromString(jsonNode3.getTextValue());
        }
        JsonNode jsonNode4 = jsonNode.get("normalizationField");
        if (jsonNode4 != null && !jsonNode4.isNull()) {
            this.j = jsonNode4.getTextValue();
        }
        JsonNode jsonNode5 = jsonNode.get("normalizationTotal");
        if (jsonNode5 != null && !jsonNode5.isNull()) {
            this.k = jsonNode5.getDoubleValue();
        }
        JsonNode jsonNode6 = jsonNode.get("minValue");
        if (jsonNode6 != null && !jsonNode6.isNull()) {
            this.e = jsonNode6.getDoubleValue();
        }
        JsonNode jsonNode7 = jsonNode.get("defaultSymbol");
        if (jsonNode7 != null && !jsonNode7.isNull()) {
            this.g = SymbolHelper.parseSymbol(jsonNode7);
        }
        JsonNode jsonNode8 = jsonNode.get("classBreakInfos");
        if (jsonNode8 == null || jsonNode8.isNull() || !jsonNode8.isArray()) {
            return;
        }
        Iterator<JsonNode> it = jsonNode8.iterator();
        while (it.hasNext()) {
            ClassBreak classBreak = new ClassBreak(it.next());
            this.f.put(Double.valueOf(classBreak.b), classBreak);
        }
    }

    @Deprecated
    public Symbol getSymbol(Graphic graphic) {
        return getSymbol((Feature) graphic);
    }

    @Override // com.esri.core.renderer.Renderer
    public Symbol getSymbol(Feature feature) {
        Symbol symbol = this.g;
        Object attributeValue = feature.getAttributeValue(this.d);
        if (attributeValue != null) {
            try {
                double parseDouble = Double.parseDouble(attributeValue.toString());
                int i = AnonymousClass1.a[getNormalizationType().ordinal()];
                if (i == 1) {
                    parseDouble = Math.log10(parseDouble);
                } else if (i == 2) {
                    Object attributeValue2 = feature.getAttributeValue(getNormalizationField());
                    if (attributeValue2 != null) {
                        parseDouble /= Double.parseDouble(attributeValue2.toString());
                    }
                } else if (i == 3) {
                    parseDouble = (parseDouble / getNormalizationTotal()) * 100.0d;
                }
                SortedMap<Double, ClassBreak> tailMap = this.f.tailMap(Double.valueOf(parseDouble));
                ClassBreak classBreak = (tailMap == null || tailMap.isEmpty()) ? null : this.f.get(tailMap.firstKey());
                if (classBreak != null) {
                    return classBreak.getSymbol();
                }
                return null;
            } catch (NumberFormatException unused) {
                return symbol;
            }
        }
        return symbol;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.esri.core.renderer.ClassBreaksRenderer$1  reason: invalid class name */
    /* loaded from: classes.dex */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[NormalizationType.values().length];
            a = iArr;
            try {
                iArr[NormalizationType.ByLog.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[NormalizationType.ByField.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[NormalizationType.ByPercentOfTotal.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    public String getField() {
        return this.d;
    }

    public void setField(String str) {
        this.d = str;
    }

    public double getMinValue() {
        return this.e;
    }

    public void setMinValue(double d) {
        this.e = d;
    }

    public TreeMap<Double, ClassBreak> getClassBreakInfos() {
        return this.f;
    }

    public void setClassBreakInfos(TreeMap<Double, ClassBreak> treeMap) {
        this.f = treeMap;
    }

    public boolean addClassBreak(ClassBreak classBreak) {
        return (classBreak == null || this.f.put(Double.valueOf(classBreak.b), classBreak) == null) ? false : true;
    }

    public boolean removeClassBreak(ClassBreak classBreak) {
        return (classBreak == null || this.f.remove(Double.valueOf(classBreak.b)) == null) ? false : true;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.esri.core.renderer.BaseRenderer
    public void toJson(JsonGenerator jsonGenerator) throws Exception {
        super.toJson(jsonGenerator);
        jsonGenerator.writeStringField(WebMapQuery.PARAM_FIELD, this.d);
        if (this.i != NormalizationType.None) {
            jsonGenerator.writeStringField("normalizationType", this.i.getValue());
            if (this.i == NormalizationType.ByField) {
                jsonGenerator.writeStringField("normalizationField", this.j);
            } else if (this.i == NormalizationType.ByPercentOfTotal) {
                jsonGenerator.writeNumberField("normalizationTotal", this.k);
            }
        }
        if (this.g != null) {
            jsonGenerator.writeFieldName("defaultSymbol");
            jsonGenerator.writeRawValue(this.g.toJson());
        }
        String str = this.h;
        if (str != null && str.length() > 0) {
            jsonGenerator.writeStringField("defaultLabel", this.h);
        }
        jsonGenerator.writeNumberField("minValue", this.e);
        jsonGenerator.writeFieldName("classBreakInfos");
        jsonGenerator.writeStartArray();
        boolean z = true;
        for (ClassBreak classBreak : this.f.values()) {
            if (z) {
                z = false;
            } else {
                jsonGenerator.writeRaw(",");
            }
            jsonGenerator.writeRaw(classBreak.toJson());
        }
        jsonGenerator.writeEndArray();
    }

    public List<FeatureTemplate> toTemplates(Geometry.Type type) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new FeatureTemplate(this.d, TYPE, new HashMap(), d.b(type)));
        return arrayList;
    }

    public Symbol getDefaultSymbol() {
        return this.g;
    }

    public void setDefaultSymbol(Symbol symbol) {
        this.g = symbol;
    }

    public String getDefaultLabel() {
        return this.h;
    }

    public void setDefaultLabel(String str) {
        this.h = str;
    }

    public NormalizationType getNormalizationType() {
        return this.i;
    }

    public void setNormalizationType(NormalizationType normalizationType) {
        this.i = normalizationType;
    }

    public String getNormalizationField() {
        return this.j;
    }

    public void setNormalizationField(String str) {
        this.j = str;
    }

    public double getNormalizationTotal() {
        return this.k;
    }

    public void setNormalizationTotal(double d) {
        this.k = d;
    }
}
